import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—07—06
 * Time: 14:31
 */
public class Demo02 {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(22);
        arrayList.add(2232);
        System.out.println(arrayList);

        ArrayList<Integer> arrayList2 = new ArrayList<>(15);
        ArrayList<Integer> arrayList3 = new ArrayList<>(arrayList);
        LinkedList<Integer> list = new LinkedList<>();
        ArrayList<Integer> arrayList4 = new ArrayList<>(list);
        System.out.println("====1.for循环+下标=====");
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i) + " ");
        }
        System.out.println();
        System.out.println("=====2.for-each======");
        for (int x: arrayList) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("====3.使用迭代器=======");
        Iterator<Integer> it = arrayList.iterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }
    }
}
